package com.kai.awt.component;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @Author Mr.Yan
 * @create 2022/3/20 15:00
 * @description:
 */
public class Demo3 {

    public static void main(String[] args) {
        Frame frame = new Frame("filedialog");

        FileDialog d1 = new FileDialog(frame, "打开", FileDialog.LOAD);
        FileDialog d2 = new FileDialog(frame, "保存", FileDialog.SAVE);



        Button button1 = new Button("打开");
        Button button2 = new Button("保存");

        frame.add(button1,BorderLayout.NORTH);
        frame.add(button2);

        button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {

                d1.setVisible(true);

                String directory = d1.getDirectory();
                String file = d1.getFile();
                System.out.println(directory+":"+file);
            }
        });
        button2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                d2.setVisible(true);

                String directory = d2.getDirectory();
                String file = d2.getFile();
                System.out.println(directory+":"+file);

            }
        });

        frame.pack();
        frame.setVisible(true);


    }
}
